package com.typy.www.tpay.ui.adapter;

import android.content.Context;
import android.os.CountDownTimer;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * Created by 13799 on 2018/7/14.
 */

public  class MyAdapter {
////    private List<TimerItem> mDatas;
//    private Context mContext; //用于退出 Activity,避免 Countdown，造成资源浪费。
//    private SparseArray<CountDownTimer> countDownCounters;
//
//    public MyAdapter(Context mContext, List<TimerItem> mDatas) {
//        this.mContext = mContext;
//        this.mDatas = mDatas;
//        this.countDownCounters = new SparseArray<>();
//    }
//
//    /**
//     * 清空当前 CountTimeDown 资源
//     */
//    public void cancelAllTimers() {
//        if (countDownCounters == null) {
//            return;
//        }
//        for (int i = 0, length = countDownCounters.size(); i < length; i++) {
//            CountDownTimer cdt = countDownCounters.get(countDownCounters.keyAt(i));
//            if (cdt != null) {
//                cdt.cancel();
//            }
//        }
//    }
//
//    @Override
//    public int getCount() {
//        if (mDatas != null && !mDatas.isEmpty()) {
//            return mDatas.size();
//        }
//        return 0;
//    }
//
//    @Override
//    public Object getItem(int position) {
//        if (mDatas != null && !mDatas.isEmpty()) {
//            return mDatas.get(position);
//        }
//        return null;
//    }
//
//    @Override
//    public long getItemId(int position) {
//        return position;
//    }
//
//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
////        final ViewHolder viewHolder;
////        if (convertView == null) {
////            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_common, parent, false);
////            viewHolder = new ViewHolder();
////            viewHolder.statusTv = (TextView) convertView.findViewById(R.id.tv_status);
////            viewHolder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
////            convertView.setTag(viewHolder);
////        } else {
////            viewHolder = (ViewHolder) convertView.getTag();
////        }
//        final TimerItem data = mDatas.get(position);
//        viewHolder.statusTv.setText(data.name);
//        CountDownTimer countDownTimer = countDownCounters.get(viewHolder.timeTv.hashCode());
//        if (countDownTimer != null) {
//            //将复用的倒计时清除
//            countDownTimer.cancel();
//        }
//        long timer = data.expirationTime;
//        timer = timer - System.currentTimeMillis();
//        //expirationTime 与系统时间做比较，timer 小于零，则此时倒计时已经结束。
//        if (timer > 0) {
//            countDownTimer = new CountDownTimer(timer, 1000) {
//                public void onTick(long millisUntilFinished) {
//                    viewHolder.timeTv.setText(TimeTools.getCountTimeByLong(millisUntilFinished));
//                }
//
//                public void onFinish() {
//                    viewHolder.timeTv.setText("00:00:00");
//                    viewHolder.statusTv.setText(data.name + ":结束");
//                }
//            }.start(); //将此 countDownTimer 放入list.
//            countDownCounters.put(viewHolder.timeTv.hashCode(), countDownTimer);
//        } else {
//            viewHolder.timeTv.setText("00:00:00");
//            viewHolder.statusTv.setText(data.name + ":结束");
//        }
//        return convertView;
//    }
//
////    public class ViewHolder {
////        public TextView statusTv;
////        public TextView timeTv;
////    }
}


